package com.hspedu.tankgame5;

import java.util.Vector;

/**
 * @author DL5O
 * @version 1.0
 */
public class Shot implements Runnable {
    private int x;
    private int y;
    private int shotSpeed = 20;
    private int direct;//子弹的方向
    boolean isLive = true;


    public Shot(int x, int y, int direct) {
        this.x = x;
        this.y = y;
        this.direct = direct;
    }

    public void moveUp() {
        y -= shotSpeed;
    }

    public void moveRight() {
        x += shotSpeed;
    }

    public void moveDown() {
        y += shotSpeed;
    }

    public void moveLeft() {
        x -= shotSpeed;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getShotSpeed() {
        return shotSpeed;
    }

    public void setShotSpeed(int shotSpeed) {
        this.shotSpeed = shotSpeed;
    }

    public int getDirect() {
        return direct;
    }

    public void setDirect(int direct) {
        this.direct = direct;
    }

    public boolean isLive() {
        return isLive;
    }

    public void setLive(boolean live) {
        isLive = live;
    }

    @Override
    public void run() {
        while(true){
            switch (getDirect()){
                case 0://向上移动
                    moveUp();
                    break;
                case 1://向右
                    moveRight();
                    break;
                case 2://下
                    moveDown();
                    break;
                case 3://上
                    moveLeft();
                    break;
                default:
                    break;
            }

            if(!(this.x >=0 && this.x <= 1000 && this.y >=0 && this.y <= 750 && isLive)){
                isLive = false;
                break;
            }
        }

    }
}
